package xxhci.oracle.apps.XXIERP.PDSPSample.server;

import java.sql.SQLException;

import oracle.apps.fnd.common.MessageToken;
import oracle.apps.fnd.framework.OAException;
import oracle.apps.fnd.framework.OAViewObject;
import oracle.apps.fnd.framework.server.OAApplicationModuleImpl;
import oracle.apps.fnd.framework.server.OADBTransactionImpl;

import oracle.jbo.Row;

import oracle.jdbc.OracleCallableStatement;




// ---------------------------------------------------------------------
// ---    File generated by Oracle ADF Business Components Design Time.
// ---    Custom code may be added to this class.
// ---    Warning: Do not modify method signatures of generated methods.
// ---------------------------------------------------------------------
public class PDSample_AMImpl extends OAApplicationModuleImpl {
    /**This is the default constructor (do not remove)
     */
    public PDSample_AMImpl() {
    }

    /**Container's getter for XxierpPDSP_VO1
     */
    public XxierpPDSP_VOImpl getXxierpPDSP_VO1() {
        return (XxierpPDSP_VOImpl)findViewObject("XxierpPDSP_VO1");
    }

    /**Sample main for debugging Business Components code using the tester.
     */
    public static void main(String[] args) {
        launchTester("xxhci.oracle.apps.XXIERP.PDSPSample.server", /* package name */
      "PDSample_AMLocal" /* Configuration Name */);
    }
    
    public void insertRow()
      {
      // Create row with StoredProcedure
          try
          {
              XxierpPDSP_EOImpl eoIMPObj=new XxierpPDSP_EOImpl();
              OADBTransactionImpl oadbtransactionimpl = (OADBTransactionImpl)getDBTransaction();
              String s = "begin xxierp_oaf_plsql_demo_prc(p_person_id => :1, p_first_name => :2, p_last_name => :3); end; ";
              OracleCallableStatement oraclecallablestatement = (OracleCallableStatement)oadbtransactionimpl.createCallableStatement(s, -1);
              oraclecallablestatement.setNUMBER(1, eoIMPObj.getPersonId());
              oraclecallablestatement.setString(2, eoIMPObj.getFirstName());
              oraclecallablestatement.setString(3, eoIMPObj.getLastName());
              oraclecallablestatement.execute();
          }
          catch(SQLException sqlexception)
          {
              throw OAException.wrapperException(sqlexception);
          }
          catch(Exception exception)
          {
              throw OAException.wrapperException(exception);
          }
      }
      
      
    public void CreatePersonDetails() {
    
                      OAViewObject vo = (OAViewObject)getXxierpPDSP_VO1();
                    // Per the coding standards, this is the proper way to initialize a
                    // VO that is used for both inserts and queries. See View Objects
                   // in Detail in the Developer's Guide for additional information.
                   if (!vo.isPreparedForExecution())
                    {
                    vo.executeQuery();
                     }
                    Row row = vo.createRow();
                 vo.insertRow(row);
                    // Required per OA Framework Model Coding Standard M69
                  row.setNewRowState(Row.STATUS_INITIALIZED);
       
    }
    
    public void createPersonMethod(String pAction, String pPersonId)
    {
        XxierpPDSP_VOImpl pervo=getXxierpPDSP_VO1();
        if(!pervo.isPreparedForExecution())
            pervo.executeQuery();
            Row prow = pervo.createRow();
            pervo.insertRow(prow);
            prow.setNewRowState(Row.STATUS_INITIALIZED);
    }
    
    
    public void createRadio()
    {
        XxTestRadioVOImpl pervo=getXxTestRadioVO1();
        if(!pervo.isPreparedForExecution())
            pervo.executeQuery();
            Row prow = pervo.createRow();
            pervo.insertRow(prow);
            prow.setNewRowState(Row.STATUS_INITIALIZED);
    }
    public void updatePersonMethod( String pAction, String pPersonId) {
    try{

        XxierpPDSP_VOImpl pervo=getXxierpPDSP_VO1();
        String existingWhereClause = pervo.getWhereClause();
        pervo.setWhereClauseParams(null);
        pervo.setWhereClause("person_id = :1");
        pervo.setWhereClauseParam(0,pPersonId);
        pervo.executeQuery();
        pervo.setWhereClauseParams(null);
        pervo.setWhereClause(existingWhereClause);
    }
    catch(Exception ex)
    {
        throw OAException.wrapperException(ex);
    }
    }
    public void updateRadio( String pPersonId) {
    try{
       
        XxTestRadioVOImpl pervo=getXxTestRadioVO1();
        String existingWhereClause = pervo.getWhereClause();
        pervo.setWhereClauseParams(null);
        pervo.setWhereClause("id = :1");
        pervo.setWhereClauseParam(0,pPersonId);
        pervo.executeQuery();
        pervo.setWhereClauseParams(null);
        pervo.setWhereClause(existingWhereClause);
    }
    catch(Exception ex)
    {
        throw OAException.wrapperException(ex);
    }
    }
    
    public void savePersonToDatabase() {
        getTransaction().commit();
    }
    
    public void deletePersonDetails(String pAction,String pPersonId)
    { 
    System.out.println("Delete Person details from searchpage");
    XxierpPDSP_VOImpl pervo=getXxierpPDSP_VO1();
    Row row[]=pervo.getAllRowsInRange();
    for(int i=0;i<row.length;i++)
    {
        XxierpPDSP_VORowImpl rowi=(XxierpPDSP_VORowImpl)row[i];
       
        if(rowi.getPersonId().toString().equals(pPersonId)) 
        {
            System.out.println("Delete PersonId =>"+rowi.getPersonId());
            rowi.remove();
            getOADBTransaction().commit();
            return;
        }
      
            
    }
    }
    
  /*  public void deletePersonDetails2(String pAction,String pPersonId)
    { 
    System.out.println("Delete Person details from searchpage");
    ViewObjImpl pervo=getViewObj1();
    Row row[]=pervo.getAllRowsInRange();
    for(int i=0;i<row.length;i++)
    {
        XxierpPDSP_VORowImpl rowi=(XxierpPDSP_VORowImpl)row[i];
       
        if(rowi.getPersonId().toString().equals(pPersonId)) 
        {
            System.out.println("Delete PersonId =>"+rowi.getPersonId());
            rowi.remove();
            getOADBTransaction().commit();
            return;
        }
      
            
    }
    }
    */
        public void deletePerson(String strId)
            {
           
                OAViewObject vo = (OAViewObject) getXxierpPDSP_VO1();
                Row row[]=vo.getAllRowsInRange();
                for(int i=0;i<row.length;i++)
                {
                //String str= (XxierpPersonDetailsVORowImpl)row[i].getAttribute("PersonId").toString();
                if(row[i].getAttribute("PersonId").toString().equals(strId))
                    {
                        row[i].remove();
                    }
               
                }
    
    }


    /**Container's getter for XxTestRadioVO1
     */
    public XxTestRadioVOImpl getXxTestRadioVO1() {
        return (XxTestRadioVOImpl)findViewObject("XxTestRadioVO1");
    }
}
